import type { Router } from 'vue-router';

const APP_ROUTER_KEY = Symbol('appRouter');

export function setAppRouter(router: Router) {
  Object.defineProperty(window, APP_ROUTER_KEY, {
    value: router,
    writable: false,
    enumerable: false,
    configurable: false,
  });
}

/**
 * 获取应用的vueRouter实例, 可以在任意地方使用，不限于setup环境
 */
export function getAppRouter() {
  return (window as any)[APP_ROUTER_KEY] as Router;
}
